package cn.uidcc.websocket.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by user on 2021/6/26.
 */
@Component
public class WebSocketTask
{
    private static final Logger logger = LoggerFactory.getLogger(WebSocketTask.class);

    @Autowired
    private WebSocketServer webSocketServer;

    /**
     * 服务器主动向客户端推送消息
     */
    @Scheduled(cron = "0/30 * * * * ?")
    public void initiativeSendMsg()
    {
        logger.info("服务器主动向客户端推送消息.");
        webSocketServer.sendToAll("test");
    }
}
